<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>进货</title>
    <%
        String path=request.getContextPath();
        String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <base href="<%=basePath%>">
    <title>Title</title>
    <link rel="stylesheet" href="layui-v2.6.5/layui/css/layui.css">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="layui-v2.6.5/layui/layui.js"></script>
</head>
<body>
<div>
    <br>
    <br>
    <form action="" class="layui-form" method="post" id="form_">
        <input type="hidden" name="action" value="add">
        <div class="layui-form-item">
            <label class="layui-form-label">商品编号:</label>
            <div class="layui-input-inline">
                <input type="text" name="pid" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">进货单价:</label>
            <div class="layui-input-inline">
                <input type="text" name="prime" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">进货数量:</label>
            <div class="layui-input-inline">
                <input type="text" name="enumber" placeholder="请输入" autocomplete="off" class="layui-input" lay-verify="number">
            </div>
        </div>
        <button lay-submit class="layui-btn layui-btn-normal" lay-filter="add">添加</button>
    </form>
</div>
<script>
    layui.use(['element', 'layer','form'], function(){
        var form = layui.form;
        var $ = layui.jquery
            ,element = layui.element
            ,layer = layui.layer;

        $(function (){
            $("#form_").submit(function (){
                $.get("manager/purchaseServlet", $(this).serialize(), function (data){
                    if(data.flag){
                        layer.msg('入库成功!');
                        // layer.msg(data.errorMsg);
                    }
                    else {
                        layer.msg(data.errorMsg);
                    }
                })
                return false;
            })
        })

        // form.on('submit(add)', function(data){
        //     var pid=$("input[name='pid']").val();
        //     var prime=$("input[name='prime']").val();
        //     var enumber=$("input[name='enumber']").val();
        //     $.ajax({
        //         url:"manager/purchaseServlet?action=add&pid="+pid+"&prime="+prime+"&enumber="+enumber,
        //         type:"post",
        //         contentType:'application/json;charset=utf-8',
        //         dataType:"text",
        //         data:{
        //         },
        //         success:function (res) {
        //             layer.msg('入库成功');
        //         },
        //         error:function (res) {
        //             layer.msg('入库失败');
        //         }
        //     })
        //     return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        // });
    });
</script>
</body>
</html>